package cn.kgc.springhouse.controller;


import cn.kgc.springhouse.entity.Houseinfo;
import cn.kgc.springhouse.service.HouseinfoService;
import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwr
 * @since 2024-04-09
 */
@CrossOrigin
@RestController
@RequestMapping("/springhouse/houseinfo")
public class HouseinfoController {

    @Resource
    HouseinfoService houseinfoService;

    @GetMapping("/select")
    public R select(@RequestParam(value = "keyWord",required = false,defaultValue = "") String keyWord,
                    @RequestParam(value = "pageSize",required = false,defaultValue = "3") Integer pageSize,
                    @RequestParam(value = "pageIndex",required = false,defaultValue = "1") Integer pageIndex){
        PageInfo<Houseinfo> pageInfo=houseinfoService.selectPageList(keyWord,pageIndex,pageSize);
        return R.ok(pageInfo).setCode(20000);
    }

    @GetMapping("/select2")
    public R select2(@RequestParam(value = "keyWord",required = false,defaultValue = "") String keyWord){
        List<Houseinfo> houseinfos = houseinfoService.select2(keyWord);
        return R.ok(houseinfos);
    }


    @PostMapping("/add")
    public R add(@RequestBody Houseinfo houseinfo){
        boolean b = houseinfoService.save(houseinfo);
        return R.ok(b);
    }

    @GetMapping("/get/{id}")
    public R get(@PathVariable("id") Integer id){
        return R.ok(houseinfoService.getHouseById(id));
    }

    @PostMapping("/update")
    public R update(@RequestBody Houseinfo houseinfo){
        return R.ok(houseinfoService.updateById(houseinfo));
    }

    @GetMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        return R.ok(houseinfoService.removeById(id));
    }
}

